home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / PAS_0793 / STRWRT.ASM < prev    next >
Assembly Source File  |  1993-08-01  |  2KB  |  71 lines

  1. ;─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. ;Msg  : 343 of 374
  3. ;From : Wilbert van Leijen                  2:281/256.14         26 Jun 93  19:36
  4. ;To   : BRIAN PAPE
  5. ;Subj : WriteString routine (asm)
  6. ;────────────────────────────────────────────────────────────────────────────────
  7. ;21 Jun 93, BRIAN PAPE writes to ALL:
  8. ;
  9. ; BP> Ok, I was writing a little program that I was trying to make as small as
  10. ; BP> possible, so I wrote this little WriteString function.
  11. ;
  12. ;Beat this (32 bytes):
  13. ;
  14. LOCALS
  15.  
  16.            MODEL   SMALL
  17. .DATA
  18.  
  19. CrLf       DB      13, 10, '$'
  20.  
  21. .CODE
  22.            Public  STRWRITE, STRWRITELN
  23.  
  24. ;  Turbo Pascal declaration:
  25. ;  Procedure StrWrite(s : PChar); Near; External;
  26. ;  Procedure StrWriteLn(s : PChar); Near; External;
  27.  
  28. ;  C small model declaration:
  29. ;  extern void near pascal STRWRITE(char far *s);
  30. ;  extern void near pascal STRWRITELN(char far *s);
  31.  
  32. STRWRITELN PROC
  33.            STC
  34.            JMP     Short @@1
  35.  
  36. STRWRITE:  CLC
  37. @@1:       MOV     BX, SP
  38.            PUSH    DI  DS
  39.            PUSHF
  40.            LES     DI, SS:[BX+2]
  41.            LDS     DX, SS:[BX+2]
  42.  
  43. ;  Scan up to 64 kByte for null byte
  44.  
  45.            MOV     CX, -1
  46.            MOV     AX, 0900h
  47.            CLD
  48.            REPNE   SCASB
  49.            DEC     DI
  50.  
  51. ;  Put end of string marker, display string
  52.  
  53.            MOV     Byte Ptr [DI], '$'
  54.            INT     21h
  55.  
  56. ;  Restore null byte
  57.  
  58.            SUB     Byte Ptr [DI], '$'
  59.  
  60. ;  Write out new line if carry flag is set
  61.  
  62.            POPF
  63.            POP     DS
  64.            JNC     @@2
  65.            LEA     DX, CrLf
  66.            INT     21h
  67. @@2:       POP     DI
  68.            RETN    4
  69. STRWRITELN ENDP
  70.  
  71.            END